//
//  SDHSportsMineHeaderButton.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/6.
//

#import "SDHSportsMineHeaderButton.h"

@implementation SDHSportsMineHeaderButton

- (id)init {
    if (self = [super init]) {
//        self.backgroundColor = [UIColor redColor];
        UIView *btnBgView = [UIView new];
        btnBgView.backgroundColor = [UIColor whiteColor];
        btnBgView.clipsToBounds = YES;
        btnBgView.layer.cornerRadius = 10;
        [self addSubview:btnBgView];
        
        UIImageView *imgView = [UIImageView new];
        imgView.image = [UIImage imageNamed:@"guanzhu"];
        [self addSubview:imgView];
        self.btnImg = imgView;
        
        UILabel *label = [UILabel new];
        label.text = @"Follow";
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor blackColor];
//        label.backgroundColor = [UIColor greenColor];
        [self addSubview:label];
        self.btnTitle = label;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click:)];
        [self addGestureRecognizer:tap];
        
        __weak typeof(self) weakSelf = self;
        [btnBgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf);
            make.top.equalTo(weakSelf);
            make.width.equalTo(weakSelf);
            make.height.equalTo(weakSelf.mas_width);
        }];
        
        [self.btnImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(weakSelf);
            make.centerY.equalTo(btnBgView);
            make.edges.equalTo(btnBgView).insets(UIEdgeInsetsMake(0, 0, 0, 0));
        }];
        
        [self.btnTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(weakSelf);
            make.top.equalTo(btnBgView.mas_bottom).offset(5);
        }];
    }
    
    return self;
}

- (void)click:(UITapGestureRecognizer *)gesture {
    if (self.block) {
        self.block(self.tag);
    }
}

@end
